ValidDotStackObject <- function(object) {
  original <- object@original
  lname <- length(object@name)
  x <- object@x
  y <- object@y
  h <- object@h
  key <- object@key
  ok <- object@ok
  color <- object@color
  shape <- object@shape
  n <- length(original)
  nok <- length(ok)

  results <- c(
    if (identical(n, length(key))) TRUE else paste(
      "Lengths of 'original' (", n, ") and of 'key' (",
      length(key), ") should be equal.", sep = ""),
    if (identical(lname, 1L)) TRUE else paste(
       "Length of 'name' (", lname, ") must be 1.", sep = ""),
    if (nok <= n) TRUE else paste("Length of 'ok' (", nok,
      ") should be equal or less than length of 'original' (",
      n, ").", sep = ""),
    if (length(color) %in% c(1, n)) TRUE else paste(
      "Length of 'color' (", length(color),
      ") must be 1 or ", n, ".", sep = ""),
    if (length(shape) %in% c(0L, 1L, n)) TRUE else paste(
      "Length of 'shape' (", length(shape),
      ") must be 0, 1 or ", n, ".", sep = ""),
    if (identical(length(x), nok)) TRUE else paste(
      "Lengths of 'x' (", length(x), ") and 'ok' (",
      nok, ") should be equal.", sep = ""),
    if (identical(length(y), nok)) TRUE else paste(
      "Lengths of 'y' (", length(y), ") and 'ok' (",
      nok, ") should be equal.", sep = ""),
    if (identical(length(h), 1L)) TRUE else paste(
      "'h' must be of length 1 not (", length(h), ").", sep = '')
  )
  if (isTRUE(all(as.logical(results)))) TRUE else print(results)
}

setClass("DotStack",
  representation(
    original = "numeric",
    name = "character",
    x = "numeric",
    y = "numeric",
    color = "ANY",
    shape = "ANY",
    key = "integer",
    ok = "integer",
    h = "numeric"),
  contains = "list",
  validity = ValidDotStackObject
)

ValidVAObject <- function(object) {
  noOS <- length(object@originalOS); noOD <- length(object@originalOD)
  coOS <- class(object@originalOS); coOD <- class(object@originalOD)
  nlOS <- length(object@logMAROS); nlOD <- length(object@logMAROD)
  nCV <- length(object@chart.values); nCN <- length(object@chart.nletters)

  results <- c(
    if (identical(noOS, noOD)) TRUE else paste("Lengths of 'originalOS' (",
      noOS, ") and of 'originalOD' (", noOD, ") should be equal.", sep = ""),
    if (identical(coOS, coOD)) TRUE else paste("Class of 'originalOS' (",
      coOS, ") and of 'originalOD' (", coOD, ") should be identical.", sep = ""),
    if (identical(nlOS, nlOD)) TRUE else paste("Lengths of 'logMAROS' (",
      nlOS, ") and of 'logMAROD' (", nlOD, ") should be equal.", sep = ""),
    if (identical(nCV, nCN)) TRUE else paste("Lengths of 'originalOS' (",
      noOS, ") and of 'originalOD' (", noOD, ") should be equal.", sep = "")
  )

  if (isTRUE(all(as.logical(results)))) TRUE else print(results)
}

setClass("VAObject",
  representation(
    originalOS = "ANY",
    originalOD = "ANY",
    logMAROS = "numeric",
    logMAROD = "numeric",
    chart.values = "character",
    chart.nletters = "integer",
    zero = "numeric"),
  prototype(
    originalOS = character(0),
    originalOD = character(0),
    logMAROS = numeric(0),
    logMAROD = numeric(0),
    chart.values = paste("20/",
      c(200, 100, 70, 50, 40, 30, 25, 20, 15, 10), sep = ''),
    chart.nletters = 1:10,
    zero = as.numeric(NA)),
  validity = ValidVAObject)

ValidVASummaryObject <- function(object) {
  noOS <- length(object@originalOS)
  nlogMARc <- length(object@logMAR.combined)
  nSnellenc <- length(object@snellen.combined)
  nmlogMAR <- length(object@mean.logMAR)
  nmSnellen <- length(object@mean.snellen)
  results <- c(
    if (identical(noOS, nlogMARc)) TRUE else paste(
      "Lengths of 'originalOS' (", noOS, ") and of 'logMAR.combined' (",
      nlogMARc, ") should be equal.", sep = ""),
    if (identical(noOS, nlogMARc)) TRUE else paste(
      "Lengths of 'originalOS' (", noOS, ") and of 'snellen.combined' (",
      nSnellenc, ") should be equal.", sep = ""),
    if (identical(nmSnellen, 2L)) TRUE else paste(
      "Length of 'mean.logMAR' (", nmlogMAR, ") should be equal to 2",
      sep = ""),
    if (identical(nmSnellen, 2L)) TRUE else paste(
      "Length of 'mean.snellen' (", nmSnellen, ") should be equal to 2",
      sep = "")
  )

  if (isTRUE(all(as.logical(results)))) TRUE else print(results)
}

setClass("VASummaryObject",
  representation("VAObject",
    logMAR.combined = "numeric",
    snellen.combined = "character",
    mean.logMAR = "numeric",
    mean.snellen = "character"),
  prototype(
    logMAR.combined = numeric(0),
    snellen.combined = character(0),
    mean.logMAR = numeric(0),
    mean.snellen = character(0)),
  validity = NULL)
